package SceneUnit
{
	import BasicEngine.Dispatcher;
	import BasicEngine.EntityManager;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	import Map.MapManager;

	public class PlayScene extends Sprite
	{
		public var GameMap:TileMap;
		public var MapPosX:int;
		public var MapPosY:int;
		//显示区域
		public  var rectClip:Rectangle;
		public var clip:Sprite;
		
		//显示层容器
		public var Layers:Dictionary = new Dictionary();
		
		public function PlayScene(_x:int,_y:int,_w:int,_h:int)
		{
			rectClip = new Rectangle(_x, _y, _w, _h);
			clip = new Sprite();
			clip.graphics.beginFill(0x882E0C);
			clip.graphics.drawRect(rectClip.x, rectClip.y, rectClip.width, rectClip.height);
			//addChild(clip);
			//this.mask = clip;
			
			Layers[0] = new Sprite();   //最外层背景
			Layers[1] = new Sprite();   //地面
			Layers[2] = new Sprite();   //Npc
			Layers[3] = new Sprite();   //环境
			Layers[4] = new Sprite();   //玩家
			
			for each (var item:Sprite in Layers)
			{
				addChild(item);
			}
		}
		
		public function SwitchMap(_mapName:String):void
		{
			GameMap.SwitchMap(_mapName);
		}
		
		public function SetShowClip(_x:int, _y:int, _w:int, _h:int):void
		{
			this.mask = null;
			this.removeChild(clip);
			
			rectClip.x = _x;
			rectClip.y = _y;
			rectClip.width = _w;
			rectClip.height = _h;
			
			clip = new Sprite();
			clip.graphics.beginFill(0x882E0C);
			clip.graphics.drawRect(rectClip.x, rectClip.y, rectClip.width, rectClip.height);			
			addChild(clip);
			this.mask = clip;
		}
		
		public   function FullGrain(_grain:String):void
		{
			var bmp:BitmapData = Map.MapManager.Tiles[_grain];
			this.graphics.beginBitmapFill(Map.MapManager.Tiles[_grain]);
			this.graphics.drawRect(rectClip.x, rectClip.y, rectClip.width, rectClip.height);
		}
		
		public function AddMap(_name:String):void
		{
			GameMap = new TileMap(_name);
			addChild(GameMap);
			GameMap.Init();
		}
		
		public function MoveMap(_x:int, _y:int):void
		{
			GameMap.x = _x;
			GameMap.y = _y;
		}
		
		public function DeActive():void
		{
			
		}
	}
}